home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 8: LINUX Games
/
Linux Cubed Series 8 - LINUX Games.iso
/
games
/
x11
/
strategy
/
shanghai.000
/
shanghai
/
shanghai-1.0
/
menu.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-28
|
4KB
|
132 lines
#include <time.h>
#include "board.h"
#include "forms.h"
#include "game.h"
#include "gui.h"
#include "shanghai.h"
static FD_copyright *fd_copyright = NULL;
void copyright_exitbutton(FL_OBJECT *ob,long data)
{
if (fd_copyright->copyright->close_callback != NULL)
fd_copyright->copyright->close_callback
(fd_copyright->copyright,fd_copyright->copyright->close_data);
return;
}
static int copyright_close(FL_FORM *fd_board,void *ptr)
{
fl_hide_form(fd_copyright->copyright);
fl_free_form(fd_copyright->copyright);
fd_copyright = NULL;
if (--win_count == 0)
exit(0);
return(FL_IGNORE);
}
void menu_shanghai(FL_OBJECT *ob, long data)
{
enum {mAbout};
switch (fl_get_menu(ob)-1) {
case mAbout:
if (fd_copyright)
XRaiseWindow(fl_get_display(),fd_copyright->copyright->window);
else {
fd_copyright = create_form_copyright();
win_count++;
fl_set_form_atclose(fd_copyright->copyright,copyright_close,NULL);
fl_set_form_minsize(fd_copyright->copyright,fd_copyright->copyright->w,
fd_copyright->copyright->h);
fl_set_form_maxsize(fd_copyright->copyright,fd_copyright->copyright->w,
fd_copyright->copyright->h);
fl_set_form_hotobject(fd_copyright->copyright,fd_copyright->exitbutton);
fl_show_form(fd_copyright->copyright,FL_PLACE_HOTSPOT,FL_FULLBORDER,
"Shanghai for X"); }
break;
default:
break; }
return;
}
void menu_file(FL_OBJECT *ob, long data)
{
enum {mNew,mRestart,mOpen,mClose,mQuit};
switch (fl_get_menu(ob)-1) {
case mNew: {
int seed;
FD_board * const fd_board = (FD_board *)data;
BoardRec * board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
default_isfastgame = board_rec->isfastgame;
free(board_rec);
srand(time(0)); do {seed = rand();} while (!seed);
board_rec = initialize_board_rec(fd_board,NULL,seed);
draw_all_tiles(board_rec);
break; }
case mRestart: {
FD_board * const fd_board = (FD_board *)data;
BoardRec * const board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
default_isfastgame = board_rec->isfastgame;
initialize_board_rec(fd_board,board_rec,board_rec->seed);
draw_all_tiles(board_rec);
break; }
case mOpen: {
FD_board * const fd_board = (FD_board *)data;
BoardRec * board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
default_isfastgame = board_rec->isfastgame;
new_board();
break; }
case mClose: {
FD_board *fd_board = (FD_board *)data;
if (fd_board->board->close_callback != NULL)
fd_board->board->close_callback(fd_board->board,
fd_board->board->close_data);
break; }
case mQuit:
exit(0);
default:
break; }
return;
}
void menu_options(FL_OBJECT *ob, long data)
{
enum {mUndo,mPause,mFastMoves};
switch (fl_get_menu(ob)-1) {
case mUndo: {
FD_board *fd_board = (FD_board *)data;
BoardRec *board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
game_undo_move(board_rec);
if (!board_rec->paused)
break; }
/* fall thru */
case mPause: {
FD_board *fd_board = (FD_board *)data;
BoardRec *board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
if (!!(board_rec->paused ^= 1)) {
fl_show_object(fd_board->pausebox);
if (board_rec->time > 0)
if ((board_rec->time -= time(0)) == 0)
board_rec->time = -1; }
else {
fl_hide_object(fd_board->pausebox);
if (board_rec->time < 0 && board_rec->matchcount)
if ((board_rec->time += time(0)) == 0)
board_rec->time = 1; }
update_info_box(board_rec);
break; }
case mFastMoves: {
FD_board *fd_board = (FD_board *)data;
BoardRec *board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
board_rec->isfastgame ^= 1;
update_info_box(board_rec);
break; }
default:
break; }
return;
}